package com.taofuxn.yycreazy.ui.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;

import com.google.gson.Gson;
import com.taofuxn.yycreazy.R;
import com.taofuxn.yycreazy.util.AppStyleUtil;

import butterknife.ButterKnife;

/*
 * Created by wanghuafu on 16/9/15.
 */

public abstract class BaseActivity extends AppCompatActivity {

    private AppStyleUtil mStyleUtil;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mStyleUtil = new AppStyleUtil();
        mStyleUtil.aotoLoadStyleTheme(this);

        setContentView(setContentLayout());
        ButterKnife.inject(this);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        if (toolbar != null) {
            setSupportActionBar(toolbar);

        }
        init();
    }

    protected abstract int setContentLayout();

    protected abstract void init();


    public void switchThemeTo(AppStyleUtil.StyleType mStyleType){
        mStyleUtil.switchThemeTo(mStyleType,this);
    }

    /**
     * 跳转
     */
    public void forward(Class<? extends Activity> clazz) {
        startActivity(createIntent(clazz, null));
    }

    /**
     * 跳转
     */
    public void forward(Class<? extends Activity> clazz, Bundle extras) {
        startActivity(createIntent(clazz, extras));
    }

    /**
     * 跳转
     */
    public void forward(Class<? extends Activity> clazz, Bundle extras, int requestCode) {
        startActivityForResult(createIntent(clazz, extras), requestCode);
    }

    /**
     * 跳转
     */
    public void forward(Class<? extends Activity> clazz, int requestCode) {
        startActivityForResult(createIntent(clazz, null), requestCode);
    }

    /*获取一个Gson对象*/

    private Intent createIntent(Class<?> targetClass, Bundle extras) {
        Intent intent = new Intent();
        intent.setClass(this, targetClass);
        if (extras != null) {
            intent.putExtra("BUNDLE", extras);
        }
        return intent;
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onDestroy() {
        mStyleUtil.onDetroy();
        super.onDestroy();
    }

}
